package com.ruoyi.web.controller.eamp;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.UseApply;
import com.ruoyi.common.annotation.UseLogs;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.eamp.domain.EampCarUse;
import com.ruoyi.eamp.domain.vo.EampCarListVO;
import com.ruoyi.eamp.domain.vo.EampListAndEampUse;
import com.ruoyi.eamp.service.IEampCarUseService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 车辆使用表Controller
 * 
 * @author ruoyi
 * @date 2024-08-08
 */
@RestController
@RequestMapping("/eamp/car_use")
public class EampCarUseController extends BaseController
{
    @Autowired
    private IEampCarUseService eampCarUseService;

    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询车辆使用表列表
     */
    @PreAuthorize("@ss.hasPermi('eamp:car_use:list')")
    @GetMapping("/list")
    public TableDataInfo list(EampListAndEampUse eampListAndEampUse)
    {
        startPage();
        List<EampListAndEampUse> list = eampCarUseService.selectEampCarUseList(eampListAndEampUse);
        return getDataTable(list);
    }

    /**
     * 导出车辆使用表列表
     */
    @PreAuthorize("@ss.hasPermi('eamp:car_use:export')")
    @Log(title = "车辆使用表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EampCarUse eampCarUse)
    {
        List<EampCarUse> list = eampCarUseService.selectEampCarUseList(eampCarUse);
        ExcelUtil<EampCarUse> util = new ExcelUtil<EampCarUse>(EampCarUse.class);
        util.exportExcel(response, list, "车辆使用表数据");
    }

    /**
     * 获取车辆使用表详细信息
     */
    @PreAuthorize("@ss.hasPermi('eamp:car_use:query')")
    @GetMapping(value = "/{useId}")
    public AjaxResult getInfo(@PathVariable("useId") Long useId)
    {
        return success(eampCarUseService.selectEampCarUseByUseId(useId));
    }

    /**
     * 新增车辆使用表
     */
    @PreAuthorize("@ss.hasPermi('eamp:car_use:add')")
    @Log(title = "车辆使用表", businessType = BusinessType.INSERT)
    @PostMapping
    @UseApply
    public AjaxResult add(@RequestBody EampCarUse eampCarUse)
    {
        eampCarUse.setUseApplicationTime(new Date());
        return toAjax(eampCarUseService.insertEampCarUse(eampCarUse));
    }

    /**
     * 获取用户
     */
    @GetMapping("/listUser")
    public TableDataInfo listUser()
    {
        SysUser sysUser = new SysUser();
        List<SysUser> list = sysUserService.selectAllocatedList(sysUser);
        return getDataTable(list);
    }
    /**
     * 修改车辆使用表
     */
    @PreAuthorize("@ss.hasPermi('eamp:car_use:edit')")
    @Log(title = "车辆使用表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EampCarUse eampCarUse)
    {
        eampCarUse.setUseReturnTime(new Date());
        return toAjax(eampCarUseService.updateEampCarUse(eampCarUse));
    }

    /**
     * 删除车辆使用表
     */
    @PreAuthorize("@ss.hasPermi('eamp:car_use:remove')")
    @Log(title = "车辆使用表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{useIds}")
    public AjaxResult remove(@PathVariable Long[] useIds)
    {
        return toAjax(eampCarUseService.deleteEampCarUseByUseIds(useIds));
    }

    

}
